package com.zsz.springboot.config;


import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

@Configuration  //将此类定义为配置文件
public class SystemConfig {


    @Bean
    public FilterRegistrationBean characterEncodingFilterRegistrationBean(){

        //创建字符编码过滤器
        CharacterEncodingFilter characterEncodingFilter=new CharacterEncodingFilter();
        //强制使用字符变码格式
        characterEncodingFilter.setForceEncoding(true);
        //设置使用字符编码
        characterEncodingFilter.setEncoding("UTF-8");


        FilterRegistrationBean filterRegistrationBean=new FilterRegistrationBean();

        filterRegistrationBean.setFilter(characterEncodingFilter);

        //设置字符编码过滤器路径
        filterRegistrationBean.addUrlPatterns("/*");
        return filterRegistrationBean;
    }




}
